package com.java2007.hotel.controller.user;

import cn.dsna.util.images.ValidateCode;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author Reckeys
 * @version V1.0
 * @date 2021/01/07
 **/
@WebServlet("/validatecode")
public class ValidateCodeController extends HttpServlet {

    @Override
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        ValidateCode validateCode = new ValidateCode();
        validateCode.createCode();
        String code = validateCode.getCode();
        System.out.println(code);
        request.getSession().setAttribute("code",code);
        validateCode.write(response.getOutputStream());
    }

    @Override
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}